<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <script type="text/javascript" src="./axios.min.js"></script>
    <script type="text/javascript">
        axios.get('http://localhost:3000/axios?id=123').then(function(ret) {
            // 注意data属性是固定用法，用于获取后台实际数据
            console.log(ret.data);
        });
        // GET传递参数 通过params传递参数 
        axios.get('http://localhost:3000/axios?id=123', {
            params: {
                id: 789
            }
        }).then(function(ret) {
            console.log(ret.data);
        });
        // DELETE传递参数 
        axios.delete('/adata', {
            params: {
                id: 123
            }
        }).then(ret => {
            console.log(ret.data);
        });
        // POST传递参数
        axios.post('/api/test', {
            uname: 'tom',
            pwd: 123,
        }).then(ret => {
            console.log(ret.data);
        });
        // 通过URLSearchParams传递参数
        const params = new URLSearchParams();
        params.append('uname', 'tom');
        params.append('pwd', '123');
        axios.post('/api/test', params).then(ret => {
            console.log(ret.data);
        });
        // PUT传递参数
        axios.put('/api/123', {
            uname: 'tom',
            pwd: 123
        }).then(ret => {
            console.log(ret.data);
        })
    </script>

</body>

</html>